package com.jiaai.shop.store.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.shop.store.entity.TBank;
import com.jiaai.shop.store.service.ITBankService;
import com.jiaai.wgj.common.json.RestResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2018-05-04
 */
@RestController
@RequestMapping("/app/bank")
public class TBankController {
    @Autowired
    private ITBankService bankService;

    /**
     * 查找用户的银行卡
     * @param mId
     * @return
     */
    @RequestMapping("/list")
    public  Object list(String mId){
        try {
            EntityWrapper wrapper=new EntityWrapper();
            wrapper.eq("mId",mId);
            return RestResultGenerator.genSuccessResult(bankService.selectList(wrapper));
        }catch (Exception e){
            return RestResultGenerator.genSuccessResult(null);
        }
    }

    /**
     * 添加银行卡
     * @param bank
     * @return
     */
    @RequestMapping("/add")
    public  Object add(@RequestBody TBank bank){
        try {
            bankService.insert(bank);
            return RestResultGenerator.genSuccessResult("ok");
        }catch (Exception e){
            return RestResultGenerator.genErrorResult("error");
        }

    }


    @RequestMapping("info/{bankId}")
    public  Object inof(@PathVariable("bankId") Integer bankId){
         return  RestResultGenerator.genSuccessResult(bankService.selectById(bankId));
    }

}
